
Imports System
Imports System.Configuration
Imports MyClasses
Imports DAL
Imports System.Text
Imports BAL

Public Class FrmStockAdjust

#Region "Declaration"


    Private intTotalColumns As Integer = 24      'Sale Item's no of Columns    


    Private intGrdCntRows As Integer = 1
    'Private intCrntItmCnt As Integer             'Used to show No of Active Items  in Current Counter
    Private BtLoading As Boolean                    'Variable is used to avoid unNecessary loops/events/execution while setting or Loading the Data                     



    Private intColor As Integer = 0
    Private IntItem As Integer = 0


    Private intFromGodownID As Integer = 0
    Private intToGodownID As Integer = 0


    Private intPackSizeID As Integer = 0
    Private intPackUpdateDtl_PK As Integer = 0
    Private intToPackUpdateDtl_PK As Integer = 0
    Private intPackingID As Integer = 0
    Private intVoucherID As Integer
    Private intStock As Integer = 0
    Private dtbStockItems As DataTable
    Private blnIsColor As Boolean = True

    Structure StructTaxDetails
        Dim intTax As Integer
        Dim StrTaxValue As Double
        Dim StrTotalTaxableAmt As Double
        Dim strTotalTaxApplied As Double
    End Structure
#End Region '"DECLARATION"

#Region " Form( & control) Events"
    Private Sub frmSale_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            'If DSale.GetCounterDetails().Rows.Count > 0 Then
            '    'Select Case MessageBox.Show(BCommon.GetMessage(10327), BCommon.GetConfigValues("MsgTitle"), MessageBoxButtons.YesNoCancel)
            '    Select Case BCommon.ShowMsgError(10327, "YNC")
            '        Case Windows.Forms.DialogResult.Yes      'SAVE All COUNTER DATA & CLOSE.
            '            'save data
            '            BCommon.ShowMsgError(3)
            '        Case Windows.Forms.DialogResult.No       'CLOSE THE FORM
            '            'NO NEED TO CODE
            '        Case Windows.Forms.DialogResult.Cancel   'CANCEL THE FORM CLOSE EVENT
            '            e.Cancel = True
            '    End Select
            'End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "frmSale_FormClosing")
        End Try
    End Sub

    Private Sub frmSale_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            BtLoading = True
            BCommon.SetFormStandards(Me)
            Call DisplayData()
            TxtFromGodown.Focus()

            BtLoading = False

        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "frmSale_Load")
        End Try
    End Sub
#End Region

#Region "GRID SETTINGS"

    Private Sub SetGrids()
        Try
            'ITEM DISPLAY GRID
            SetDataTable()
            With fgItems
                .Left = pnlMain.Left + 5
                .Width = pnlMain.Width - 1
                .RowHeadersVisible = False
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AllowUserToOrderColumns = False
                .AllowUserToResizeRows = False
                .AllowUserToResizeColumns = False

                '.AllowDelete = True
                .RowCount = intGrdCntRows
                '.Cols.Fixed = 0
                .ColumnCount = intTotalColumns
                .ScrollBars = ScrollBars.Both
                '.AllowAddNew = False
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect




                'HIDDEN COLUMNS
                For intcnt As Integer = 0 To .ColumnCount - 1

                    .Columns(intcnt).Visible = False
                    .Columns(intcnt).ReadOnly = True
                    .Columns(intcnt).Width = 0

                    '  .Width = 0
                Next
                Call SetGridCaptions()
                .Columns(ItemGridColumns.CODE).Visible = True
                .Columns(ItemGridColumns.ITEMNAME).Visible = True
                .Columns(ItemGridColumns.CLRCODE).Visible = True
                .Columns(ItemGridColumns.CLRDESC).Visible = True
                .Columns(ItemGridColumns.PACK).Visible = True
                .Columns(ItemGridColumns.TOPACK).Visible = True
                .Columns(ItemGridColumns.STOCK).Visible = True
                .Columns(ItemGridColumns.QTY).Visible = True
                .Columns(ItemGridColumns.TOQTY).Visible = True
                .Columns(ItemGridColumns.FROMGODOWN).Visible = True
                .Columns(ItemGridColumns.TOGODOWN).Visible = True

                '.Columns(ItemGridColumns.DISC).Visible = False
                '.Columns(ItemGridColumns.DISC_AMT).Visible = False
                '.Columns(ItemGridColumns.RATE).Visible = False
                '.Columns(ItemGridColumns.AMOUNT).Visible = False
                '.Columns(ItemGridColumns.TAXCODE).Visible = False
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "SetGrids")
        End Try
    End Sub

    Private Sub SetColumnWidths()
        Dim intColWidth As Integer = fgItems.Width / (11 * 3) '10 number of visible columns *3
        Try
            With fgItems

                .Columns(ItemGridColumns.CODE).Width = intColWidth * 3
                .Columns(ItemGridColumns.ITEMNAME).Width = intColWidth * 6
                .Columns(ItemGridColumns.CLRCODE).Width = intColWidth * 3
                .Columns(ItemGridColumns.CLRDESC).Width = intColWidth * 3
                .Columns(ItemGridColumns.PACK).Width = intColWidth * 3
                .Columns(ItemGridColumns.TOPACK).Width = intColWidth * 3
                .Columns(ItemGridColumns.QTY).Width = intColWidth * 2
                .Columns(ItemGridColumns.FROMGODOWN).Width = intColWidth * 3
                .Columns(ItemGridColumns.TOGODOWN).Width = intColWidth * 3


                .Columns(ItemGridColumns.STOCK).Width = intColWidth * 2

                '.Columns(ItemGridColumns.DISC_AMT).Width = 0
                .Columns(ItemGridColumns.TOQTY).Width = intColWidth * 3

                .Columns(ItemGridColumns.AMOUNT).Width = 0
                '.Columns(ItemGridColumns.TAXCODE).Width = 0


                txtItemCode.Width = .Columns(ItemGridColumns.CODE).Width
                txtItemName.Width = .Columns(ItemGridColumns.ITEMNAME).Width
                txtCLRCODE.Width = .Columns(ItemGridColumns.CLRCODE).Width
                txtCLRNAME.Width = .Columns(ItemGridColumns.CLRDESC).Width
                cmbPack.Width = .Columns(ItemGridColumns.PACK).Width
                txtStock.Width = .Columns(ItemGridColumns.STOCK).Width
                txtQty.Width = .Columns(ItemGridColumns.QTY).Width
                txtToQty.Width = .Columns(ItemGridColumns.TOQTY).Width
                TxtFromGodown.Width = .Columns(ItemGridColumns.FROMGODOWN).Width
                TxtToGodown.Width = .Columns(ItemGridColumns.TOGODOWN).Width
                cmbToPack.Width = .Columns(ItemGridColumns.TOPACK).Width
                'txtDscAmt.Width = .Columns(ItemGridColumns.DISC_AMT).Width
                'txtPrice.Width = .Columns(ItemGridColumns.RATE).Width
                txtItemAmount.Width = .Columns(ItemGridColumns.AMOUNT).Width


                txtItemCode.Left = .Left
                txtItemName.Left = txtItemCode.Left + txtItemCode.Width
                txtItemName.TabIndex = txtItemCode.TabIndex + 1

                txtCLRCODE.Left = txtItemName.Left + txtItemName.Width
                txtCLRCODE.TabIndex = txtItemName.TabIndex + 1


                txtCLRNAME.Left = txtCLRCODE.Left + txtCLRCODE.Width
                txtCLRNAME.TabIndex = txtCLRCODE.TabIndex + 1

                cmbPack.Left = txtCLRNAME.Left + txtCLRNAME.Width
                cmbPack.TabIndex = txtCLRNAME.TabIndex + 1

                TxtFromGodown.Left = cmbPack.Left + cmbPack.Width
                TxtFromGodown.TabIndex = cmbPack.TabIndex + 1

                txtStock.Left = TxtFromGodown.Left + TxtFromGodown.Width
                txtStock.TabIndex = TxtFromGodown.TabIndex + 1

                txtQty.Left = txtStock.Left + txtStock.Width
                txtQty.TabIndex = txtStock.TabIndex + 1

                cmbToPack.Left = txtQty.Left + txtQty.Width
                cmbToPack.TabIndex = txtQty.TabIndex + 1


                TxtToGodown.Left = cmbToPack.Left + cmbToPack.Width
                TxtToGodown.TabIndex = cmbToPack.TabIndex + 1

                txtToQty.Left = TxtToGodown.Left + TxtToGodown.Width
                txtToQty.TabIndex = TxtToGodown.TabIndex + 1

                'txtItemAmount.Left = txtDscAmt.Left + txtDscAmt.Width
                'txtItemAmount.TabIndex = TxtFromGodown.TabIndex + 1
            End With

        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "SetColumnWidths")
        End Try
    End Sub

    Private Sub SetGridCaptions()
        Try
            With fgItems
                'SET COLUMN NAMES
                '.Columns(0).Name = "ITEMID"
                '.Columns(1).Name = "CODE"
                '.Columns(2).Name = "ITEMNAME"
                '.Columns(3).Name = "CLRCODE"
                '.Columns(4).Name = "CLRDESC"
                '.Columns(5).Name = "PACK"
                '.Columns(6).Name = "GODOWN"
                '.Columns(7).Name = "QTY"
                '.Columns(8).Name = "RATE"
                '.Columns(9).Name = "DISCVALUE"
                '.Columns(10).Name = "DISCAMT"
                '.Columns(11).Name = "AMOUNT"
                '.Columns(12).Name = "STATUS"

                '.Columns(13).Name = "CLRID"
                '.Columns(14).Name = "GODOWNID"

                '.Columns(15).Name = "STOCKDETAILS"
                '.Columns(16).Name = "TAXID"

                '.Columns(17).Name = "PACKID"
                '.Columns(18).Name = "PACKUPDATEID"
                '.Columns(19).Name = "TAXAMT"
                '.Columns(20).Name = "PACKSIZEID"
                '.Columns(19).Name = "TAXAMT"


                'SET COLUMN CAPTIONS
                .Columns(ItemGridColumns.ITEMID).HeaderText = "ITEMID"
                .Columns(ItemGridColumns.CODE).HeaderText = "CODE"
                .Columns(ItemGridColumns.ITEMNAME).HeaderText = "ITEMNAME"
                .Columns(ItemGridColumns.CLRCODE).HeaderText = "COLOR CODE"
                .Columns(ItemGridColumns.CLRDESC).HeaderText = "COLOR DESC"
                .Columns(ItemGridColumns.PACK).HeaderText = "PACK"
                .Columns(ItemGridColumns.TOPACK).HeaderText = " TO PACK"
                .Columns(ItemGridColumns.STOCK).HeaderText = "STOCK"


                .Columns(ItemGridColumns.QTY).HeaderText = "QTY"
                .Columns(ItemGridColumns.TOQTY).HeaderText = "TO QTY"
                .Columns(ItemGridColumns.FROMGODOWN).HeaderText = "FROM GODOWN"
                .Columns(ItemGridColumns.TOGODOWN).HeaderText = "TO GODOWN"
                '.Columns(ItemGridColumns.DISC).HeaderText = "DISC"
                '.Columns(ItemGridColumns.DISC_AMT).HeaderText = "DISC AMT"
                '.Columns(ItemGridColumns.AMOUNT).HeaderText = "AMOUNT"
                '.Columns(ItemGridColumns.STATUS).HeaderText = "STATUS"
                .Columns(ItemGridColumns.CLRID).HeaderText = "COLORID"
                .Columns(ItemGridColumns.GODOWNID).HeaderText = "GODOWNID"
                '.Columns(ItemGridColumns.TAXID).HeaderText = "TAX ID"
                '.Columns(ItemGridColumns.TAXAMT).HeaderText = "TAX APPLIED"
                '.Columns(ItemGridColumns.TAXCODE).HeaderText = "TAX"
                .Columns(ItemGridColumns.PACK_SIZE_ID).HeaderText = "PACK ID"
                .Columns(ItemGridColumns.PACKUPDATEID_PK).HeaderText = "PACKUPDATEID"
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "SetGridCaption")
        End Try
    End Sub

#End Region '"GRID SETTINGS"



#Region "BUTTON EVENTS"

    Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
        ClearData()
    End Sub
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Try
            ' If btStatus = 1 Then 'Current Record is Updated 
            Me.Close()   'Current Record is not updated
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "btnClose_Click")
        End Try
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            '    If btStatus = 1 Then SaveCurrentItem(intCurrentRow)
            If ValidateInfo() = True Then
                If SaveData() = 1 Then

                    'BCommon.ShowMsgError(3)
                    Call ClearData()
                    '     GetCounterData()

                End If
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "btnSaveCounter_Click")
        End Try
    End Sub
    Private Sub SubPriSetSeqID()
        Dim objStock As clsDStockTransfer = New clsDStockTransfer
        txtVoucher.Text = objStock.GetNextSeqID().ToString()

    End Sub
#End Region  '"BUTTON EVENTS"   

    Private Sub DisplayData()
        Try
            BtLoading = True
            'saleType = DocTypes.CASH_MEMO
            BCommon.SetTransationDate(dtpSaleDate)
            dtpSaleDate.Enabled = False

            SubPriSetSeqID()

            Call SetGrids()
            Call SetColumnWidths()
            BtLoading = False
            BCommon.SetTextReadOnly(txtVoucher)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "DisplayData")
        End Try
    End Sub

    Private Sub ClearData()
        Try
            BtLoading = True
            intVoucherID = 0
            subPriClearItemDtls()
            TxtFromGodown.Text = String.Empty
            TxtToGodown.Text = String.Empty
            With fgItems
                .Rows.Clear()
                .Rows.Add(intGrdCntRows)
                .Refresh()
            End With
            SubPriSetSeqID()

            BtLoading = False
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "ClearData")
        End Try
    End Sub
    Private Function SaveData() As Byte
        Try

            SetSaleItemDetails()

            Dim objdSale As clsDStockTransfer = New clsDStockTransfer()
            objdSale.SaveTransfer(dtbStockItems, intFromGodownID, intToGodownID)
            Return 1
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "SaveData")
            Return 0
        End Try
    End Function

    Private Sub btnPrint_Click(sender As System.Object, e As System.EventArgs) Handles btnPrint.Click
        Try
            '    If btStatus = 1 Then SaveCurrentItem(intCurrentRow)
            If ValidateInfo() = True Then
                SetSaleItemDetails()

                Dim objdSale As clsDStockTransfer = New clsDStockTransfer()
                objdSale.PrintTransfer(dtbStockItems, intFromGodownID, intToGodownID)

                'BCommon.ShowMsgError(3)
                Call ClearData()
                '     GetCounterData()

            End If

        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "btnSaveCounter_Click")
        End Try
    End Sub

    Private Sub SetDataTable()
        Try
            dtbStockItems = New DataTable()
            With dtbStockItems
                .Columns.Add("ITEMID")
                .Columns.Add("CODE") ' 1
                .Columns.Add("ITEMNAME") ' 2
                .Columns.Add("CLRCODE") ' 3
                .Columns.Add("CLRDESC") ' 4
                .Columns.Add("PACK") ' 5
                .Columns.Add("STOCK") ' 6
                'SCHEMEID ") ' 7
                'DISC ") ' 8

                .Columns.Add("QTY") ' 7
                .Columns.Add("Rate") ' 8
                .Columns.Add("DISC") ' 9
                .Columns.Add("DISC_AMT") ' 10

                .Columns.Add("AMOUNT") ' 11
                .Columns.Add("STATUS") ' 12

                .Columns.Add("CLRID") ' 13
                .Columns.Add("GODOWNID") ' 14

                .Columns.Add("STOCKDETAILS") ' 15
                .Columns.Add("TAXID") ' 16
                .Columns.Add("PACK_SIZE_ID") ' 17
                .Columns.Add("PACKUPDATEID_PK") ' 18
                .Columns.Add("TOPACKUPDATEID_PK") ' 19
                .Columns.Add("TAXCODE") ' 20
                .Columns.Add("PACKINGID") ' 21
                .Columns.Add("TAXAMT") ' 22
                .Columns.Add("IsTINTIN") ' 23

            End With
        Catch ex As Exception

        End Try
    End Sub

    Private Sub SetSaleItemDetails()
        dtbStockItems.Rows.Clear()
        Try
            For intCount As Integer = 0 To fgItems.Rows.Count - 1

                If fgItems.Item(ItemGridColumns.ITEMID, intCount).Value = Nothing OrElse Trim(fgItems.Item(ItemGridColumns.ITEMID, intCount).Value.ToString) = "" Then
                    Exit For
                Else
                    'Dim DtrRowToTransfer As
                    dtbStockItems.Rows.Add()

                    With dtbStockItems.Rows(intCount)
                        For intColCount As Integer = 0 To dtbStockItems.Columns.Count - 1
                            .Item(intColCount) = fgItems.Item(intColCount, intCount).Value
                        Next
                    End With
                End If
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "SetSaleItemDetails")
        End Try
    End Sub

    'Private Function SetSaleItemDetail(ByVal intRow As Integer) As DataTable

    '    Try
    '        With Item
    '            .intPackSizeID = fgItems.Item(ItemGridColumns.PACK_SIZE_ID, intRow).Value
    '            .ColorCode = fgItems.Item(ItemGridColumns.CLRID, intRow).Value
    '            .ItemID = fgItems.Item(ItemGridColumns.ITEMID, intRow).Value
    '            .Quantity = fgItems.Item(ItemGridColumns.QTY, intRow).Value
    '            .Amount = fgItems.Item(ItemGridColumns.AMOUNT, intRow).Value
    '            .dblRate = fgItems.Item(ItemGridColumns.RATE, intRow).Value
    '            .intPackUpdateDtl_PK = fgItems.Item(ItemGridColumns.PACKUPDATEID_PK, intRow).Value
    '            .dblDISCAmt = fgItems.Item(ItemGridColumns.DISC_AMT, intRow).Value
    '            .strDisc = fgItems.Item(ItemGridColumns.DISC, intRow).Value
    '            .TaxID = fgItems.Item(ItemGridColumns.TAXID, intRow).Value
    '            .TaxAmt = fgItems.Item(ItemGridColumns.TAXAMT, intRow).Value

    '        End With

    '        Return Item
    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "SetSaleItemDetail")
    '        Return Nothing
    '    End Try
    'End Function

    Private Function ValidateInfo() As Boolean
        '
        Try
            If intFromGodownID = 0 OrElse intToGodownID = 0 Then
                MessageBox.Show("PLEASE SELECT GODOWN DETAILS!!", "NGS", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TxtFromGodown.Focus()
                Return False
            End If

            If Not IsNothing(fgItems.Rows(0)) AndAlso Not IsNothing(fgItems.Item(ItemGridColumns.ITEMID, 0).Value) Then
                For intCount As Integer = 0 To fgItems.Rows.Count - 1
                    If fgItems.Item(ItemGridColumns.ITEMID, intCount).Value = Nothing OrElse Trim(fgItems.Item(ItemGridColumns.ITEMID, intCount).Value.ToString) = "" Then
                        Exit For
                    ElseIf (System.Convert.ToInt32(fgItems.Item(ItemGridColumns.QTY, intCount).Value) > System.Convert.ToInt16(fgItems.Item(ItemGridColumns.STOCK, intCount).Value)) Then
                        MessageBox.Show("CAN NOT TRANSFER QTY MORE THAN AVALAIBLE STOCK", "NGS", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                        Return False
                    End If
                Next
            Else
                MessageBox.Show("PLEASE SELECT Atleast one Item to Transfer!!", "NGS", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TxtFromGodown.Focus()
                Return False
            End If
            Return True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "ValidateInfo")
        End Try
    End Function
    Enum ItemGridColumns
        ITEMID = 0
        CODE = 1
        ITEMNAME = 2

        CLRCODE = 3
        CLRDESC = 4

        PACK = 5
        FROMGODOWN = 6
        STOCK = 7

        QTY = 8

        TOPACK = 9
        TOGODOWN = 10
        TOQTY = 11

        TO_PACK_SIZE_ID = 12
        'DISC_AMT = 10

        AMOUNT = 12
        STATUS = 14

        CLRID = 15
        GODOWNID = 16
        TOGODOWNID = 17

        STOCKDETAILS = 18
        'TAXID = 19
        PACK_SIZE_ID = 19
        PACKUPDATEID_PK = 20
        TOPACKUPDATEID_PK = 21
        'TAXCODE = 20
        PACKINGID = 22
        'TAXAMT = 22
        IsTINTIN = 23
    End Enum
#Region "COMMON SEARCH"


    Private Sub txtPartyCode_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtFromGodown.Enter, TxtToGodown.Enter, txtItemCode.Enter, txtItemName.Enter, txtCLRCODE.Enter, txtCLRNAME.Enter, txtStock.Enter
        If BtLoading Then Exit Sub
        If sender.Text.ToString = String.Empty Then
            sender.BackColor = Color.LightBlue
            SearchParty_Promoter_Site(sender)
        End If
    End Sub
    Private Sub txtCLRCODE_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtFromGodown.KeyDown, TxtToGodown.KeyDown, txtItemCode.KeyDown, txtItemName.KeyDown, txtCLRCODE.KeyDown, txtCLRNAME.KeyDown, txtStock.KeyDown
        If (cmbPack.Name <> sender.Name) AndAlso e.KeyCode = Keys.Back Then
            e.SuppressKeyPress = True
            SearchParty_Promoter_Site(sender)
        ElseIf e.KeyCode = Keys.Enter Then
            SendKeys.Send("{Tab}")
        ElseIf e.KeyCode = Keys.Tab Then
        ElseIf (cmbPack.Name <> sender.Name) Then
            e.SuppressKeyPress = True
        End If
    End Sub

    Private Function GetSearchQuery(ByVal Sender As Object, ByRef strSearchString As String) As String
        Select Case Sender.Name
            Case TxtFromGodown.Name
                strSearchString = "GODOWNTRANSFER "
                Return "SELECT DISTINCT (C.[Id]),C.[GoDownCode] AS CODE ,C.[GodownName] AS NAME  FROM  [GoDown] C  WHERE C.IsDeleted=0"
            Case TxtToGodown.Name
                strSearchString = "GODOWNTRANSFER "
                Return "SELECT DISTINCT (C.[Id]),C.[GoDownCode] AS CODE ,C.[GodownName] AS NAME  FROM  [GoDown] C  WHERE C.IsDeleted=0 AND C.ID <> " & intFromGodownID.ToString()
                'Case txtSiteCode.Name, txtSiteName.Name
                '    strSearchString = "SITE "
                '    Return " SELECT [Id],[SiteCode]AS CODE ,[SiteName] AS NAME,ISNULL(PriceListId,0) AS PriceListId  FROM [NGSPaintsDB].[dbo].[Site] WHERE [IsDeleted]=0" & IIf(intParty > 0, " AND PartyID=" & intParty.ToString, "")
                '    'Case txtPrice.Name 'PRICE LIST
                '    'CmbPriceList.Focus()    Return "SELECT [ID],[PRICELISTCODE]AS CODE ,[PRICELISTNAME] AS NAME  FROM [NGSPAINTSDB].[DBO].[PRICELIST] WHERE [ISDELETED]=0"
            Case txtItemCode.Name, txtItemName.Name
                strSearchString = "PRODUCT "
                Return "SELECT P.[Id] AS ItemID,P.[ProductCode] AS Code,P.[ProductName] AS Name, P.TAXID,P.IsColor FROM [NGSPaintsDB].[dbo].Product P WHERE ISDeleted=0 ORDER BY NAME"
            Case txtCLRCODE.Name, txtCLRNAME.Name
                If IntItem = 0 Then
                    Return ""
                End If
                strSearchString = "COLOR "
                Return "SELECT DISTINCT C.[Id],C.[ColorCode] AS CODE ,C.[ColorDescription] AS NAME  FROM [Color] AS C  INNER JOIN  PackingUpdateDetail  D ON (D.ColorID=C.ID) INNER JOIN  PackingUpdate P ON(P.ID=D.PackingUpdateId) WHERE C.[IsDeleted]=0  AND C.ID > 0 AND P.ProductID=" & IntItem.ToString
                'Case txtGoDown.Name
                '    If IntItem = 0 OrElse intColor = 0 OrElse intPackSizeID = 0 Then
                '        Return ""
                '    End If
                '    strSearchString = "GODOWN "
                '  Return "SELECT DISTINCT (C.[Id]),C.[GoDownCode] AS CODE ,C.[GodownName] AS NAME ,Stock, D.ID AS PackUpdateID,D.PackingID FROM PackingUpdateDetail D INNER JOIN [GoDown] C ON (D.GoDownID=C.ID AND D.ColorID=" & intColor & ")  INNER JOIN  PackingUpdate P ON(P.ID=D.PackingUpdateId AND P.ProductID=" & IntItem & ")  WHERE Stock > 0 AND D.PackSizeID=" & intPackSizeID.ToString()
            Case cmbPack.Name
                If IntItem = 0 OrElse (blnIsColor AndAlso intColor = 0) Then
                    Return ""
                End If

                strSearchString = "PACK "
                Return "SELECT DISTINCT S.ID, S.PackSize + ' ' + S.PackingDescription AS CODE FROM  PackingSize S INNER JOIN PackingUpdateDetail  D ON (D.PackSizeID=S.ID) INNER JOIN  PackingUpdate P ON(P.ID=D.PackingUpdateId) WHERE S.[IsDeleted]=0 AND D.Stock > 0 AND D.GodownID = " & intFromGodownID & "AND P.ProductID=" & IntItem.ToString & "  AND ColorID=" & intColor.ToString

            Case cmbToPack.Name
                If IntItem = 0 OrElse (blnIsColor AndAlso intColor = 0) Then
                    Return ""
                End If

                strSearchString = "PACK "
                Return "SELECT DISTINCT S.ID, S.PackSize + ' ' + S.PackingDescription AS CODE FROM  PackingSize S INNER JOIN PackingUpdateDetail  D ON (D.PackSizeID=S.ID) INNER JOIN  PackingUpdate P ON(P.ID=D.PackingUpdateId) WHERE S.[IsDeleted]=0 AND D.Stock > 0 AND D.GodownID = " & intFromGodownID & "AND P.ProductID=" & IntItem.ToString & "  AND ColorID=" & intColor.ToString

            Case Else
                Return ""
        End Select
    End Function

    Private Sub SearchParty_Promoter_Site(ByVal sender As Object)
        Try
            Dim TxtSearch As TextBox = sender

            Dim frmListProducts As New frmProducts
            With frmListProducts

                .Left = fgItems.Right - .Width - 5
                .Top = fgItems.Top + 25
                .intSelectedItem = 0
                Dim strSearch As String = ""
                'If TxtSearch.Name = TxtToGodown.Name Then
                '    If intFromGodownID = 0 Then
                '        MessageBox.Show("FIRST SELECT FROM GODOWN?", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '        Exit Sub
                '    End If
                'ElseIf TxtSearch.Name <> TxtFromGodown.Name AndAlso (intFromGodownID = 0 OrElse intToGodownID = 0) Then
                '    MessageBox.Show("FIRST SELECT FROM GODOWN AND TO GODOWN", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                .StrSearchQuery = GetSearchQuery(TxtSearch, strSearch)
                If .StrSearchQuery = String.Empty Then Exit Sub
                .strSearchByCode = strSearch & IIf(sender.Name.ToString.ToUpper.Contains("CODE"), "CODE:", "NAME:")

                .txtProduct.Text = TxtSearch.Text
                .ShowDialog(Me)
                'intSelectedProduct = frmListProducts.intSelectedItem
            End With


            If frmListProducts.intSelectedItem > 0 Then
                With frmListProducts.fgProducts
                    If .CurrentRow.Index >= 0 Then
                        Select Case TxtSearch.Name
                            'Case txtPartyCode.Name, txtPartyName.Name
                            '    intParty = .Item(0, .CurrentRow.Index).Value
                            '    txtPartyCode.Text = .Item(1, .CurrentRow.Index).Value
                            '    txtPartyName.Text = .Item(2, .CurrentRow.Index).Value
                            '    Dim intLocPriceListID As Integer = .Item(4, .CurrentRow.Index).Value
                            '    If intLocPriceListID > 0 Then
                            '        CmbPriceList.SelectedValue = intLocPriceListID
                            '        cmbPack_SelectionChangeCommitted(Nothing, Nothing)
                            '    End If
                            '    If saleType = DGeneral.DocTypes.QUOTATION Then
                            '        rTxtAddress.Text = funpriGetTermsAndConditions()
                            '    Else
                            '        rTxtAddress.Text = .Item(3, .CurrentRow.Index).Value
                            '    End If
                            '    lblChallanType.Text = .Item(5, .CurrentRow.Index).Value
                            '    sender.BackColor = Color.White


                            '    If txtPartyCode.Name = TxtSearch.Name Then
                            '        SendKeys.Send("{TAB}")
                            '        SendKeys.Send("{TAB}")
                            '    Else
                            '        SendKeys.Send("{TAB}")
                            '    End If
                            'Case txtPromoterCode.Name, txtPromoterName.Name
                            '    intPromoter = .Item(0, .CurrentRow.Index).Value
                            '    txtPromoterCode.Text = .Item(1, .CurrentRow.Index).Value
                            '    txtPromoterName.Text = .Item(2, .CurrentRow.Index).Value
                            '    sender.BackColor = Color.White
                            '    If txtPromoterCode.Name = TxtSearch.Name Then
                            '        SendKeys.Send("{TAB}")
                            '        SendKeys.Send("{TAB}")
                            '    Else
                            '        SendKeys.Send("{TAB}")
                            '    End If

                            'Case txtSiteCode.Name, txtSiteName.Name
                            '    intSite = .Item(0, .CurrentRow.Index).Value
                            '    txtSiteCode.Text = .Item(1, .CurrentRow.Index).Value
                            '    txtSiteName.Text = .Item(2, .CurrentRow.Index).Value
                            '    Dim intLocPriceListID As Integer = .Item(3, .CurrentRow.Index).Value
                            '    If intLocPriceListID > 0 Then
                            '        CmbPriceList.SelectedValue = intLocPriceListID
                            '        cmbPack_SelectionChangeCommitted(Nothing, Nothing)
                            '    End If
                            '    sender.BackColor = Color.White
                            '    If txtSiteCode.Name = TxtSearch.Name Then
                            '        SendKeys.Send("{TAB}")
                            '        SendKeys.Send("{TAB}")
                            '    Else
                            '        SendKeys.Send("{TAB}")
                            '    End If
                            Case txtItemCode.Name, txtItemName.Name
                                subPriClearItemDtls()
                                IntItem = .Item(0, .CurrentRow.Index).Value
                                txtItemCode.Text = .Item(1, .CurrentRow.Index).Value
                                txtItemName.Text = .Item(2, .CurrentRow.Index).Value
                                blnIsColor = .Item(4, .CurrentRow.Index).Value
                                If blnIsColor = False Then
                                    subPriUpdateFromPack()
                                End If
                                'TaxCode = GetTaxCode(intTaxID)
                                If txtItemCode.Name = TxtSearch.Name Then
                                    SendKeys.Send("{TAB}")
                                    SendKeys.Send("{TAB}")
                                Else
                                    SendKeys.Send("{TAB}")
                                End If
                            Case txtCLRCODE.Name, txtCLRNAME.Name
                                intColor = .Item(0, .CurrentRow.Index).Value
                                txtCLRCODE.Text = .Item(1, .CurrentRow.Index).Value
                                txtCLRNAME.Text = .Item(2, .CurrentRow.Index).Value
                                subPriUpdateFromPack()
                                sender.BackColor = Color.White
                                If txtCLRCODE.Name = TxtSearch.Name Then
                                    SendKeys.Send("{TAB}")
                                    SendKeys.Send("{TAB}")
                                Else
                                    SendKeys.Send("{TAB}")
                                End If
                                'cmbPack.DroppedDown = True
                            Case TxtFromGodown.Name ''
                                intFromGodownID = .Item(0, .CurrentRow.Index).Value
                                TxtFromGodown.Text = .Item(2, .CurrentRow.Index).Value
                                TxtToGodown.Text = ""
                                intToGodownID = 0
                                SendKeys.Send("{TAB}")
                            Case TxtToGodown.Name ''
                                intToGodownID = .Item(0, .CurrentRow.Index).Value
                                TxtToGodown.Text = .Item(2, .CurrentRow.Index).Value
                                'SearchVoucher()
                                sender.BackColor = Color.White
                                SendKeys.Send("{TAB}")
                            Case Else
                                Exit Sub
                        End Select
                    End If
                End With
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "showProductList")
        Finally
            sender.BackColor = Color.White
        End Try
    End Sub
#End Region
    Private Sub subPriUpdateFromPack()
        BtLoading = True
        Dim strPackQury As String = GetSearchQuery(cmbPack, "")
        Dim dtbpack As DataTable = DbHelper.ExecuteDataTable(strPackQury)
        Dim pk(0) As System.Data.DataColumn
        pk(0) = dtbpack.Columns(0)
        dtbpack.PrimaryKey = pk
        cmbPack.DataSource = dtbpack
        cmbPack.ValueMember = "ID"
        cmbPack.DisplayMember = "CODE"
        cmbPack.SelectedIndex = -1
        BtLoading = False

    End Sub
    Private Sub subPriUpdateToPack()
        BtLoading = True
        Dim strPackQury As String = GetSearchQuery(cmbToPack, "")
        Dim dtbpack As DataTable = DbHelper.ExecuteDataTable(strPackQury)
        Dim pk(0) As System.Data.DataColumn
        pk(0) = dtbpack.Columns(0)
        dtbpack.PrimaryKey = pk
        cmbToPack.DataSource = dtbpack
        cmbToPack.ValueMember = "ID"
        cmbToPack.DisplayMember = "CODE"
        cmbToPack.SelectedIndex = -1
        BtLoading = False

    End Sub

    Private Sub cmbPack_GotFocus(sender As Object, e As System.EventArgs) Handles cmbPack.GotFocus
        sender.DroppedDown = True
    End Sub
    Private Sub cmbPack_SelectionChangeCommitted(sender As Object, e As System.EventArgs) Handles cmbPack.SelectionChangeCommitted
        If BtLoading Then Exit Sub
        intPackSizeID = cmbPack.SelectedValue
        Dim objStock As clsDStockTransfer = New clsDStockTransfer()
        intStock = objStock.GetStock(intFromGodownID, intColor, intPackSizeID, IntItem)
        If intStock = 0 Then
            MessageBox.Show("SELECTED ITEM HAS NO ZERO STOCK, CAN NOT TRANSFER", "NiranjanPaints", MessageBoxButtons.OK, MessageBoxIcon.Error)
            subPriClearItemDtls()
            txtItemCode.Focus()
            Exit Sub
        End If
        txtStock.Text = intStock.ToString()
        intPackUpdateDtl_PK = objStock.GetToPackinUpdateID(intFromGodownID, intColor, intPackSizeID, IntItem).ToString()
        intToPackUpdateDtl_PK = objStock.GetToPackinUpdateID(intToGodownID, intColor, intPackSizeID, IntItem).ToString()
        If intToPackUpdateDtl_PK = 0 Then
            MessageBox.Show("SELECTED ITEM HAS NO PACKING DETAIL ENTRY FOR " & TxtToGodown.Text, "NiranjanPaints", MessageBoxButtons.OK, MessageBoxIcon.Error)
            subPriClearItemDtls()
            txtItemCode.Focus()
            Exit Sub
        End If


    End Sub


    Private Sub txtQty_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtQty.KeyDown
        If BCommon.ValidateText(txtQty.Text.Trim, e.KeyCode, "NUM", False) = False Then
            e.SuppressKeyPress = True
        ElseIf e.KeyCode = Keys.Enter Then
            SendKeys.Send("{TAB}")
        End If
    End Sub
    Private Sub txtQty_LostFocus(sender As Object, e As System.EventArgs) Handles txtQty.LostFocus
        Dim IntQty As Integer = System.Convert.ToInt16(txtQty.Text)
        If IntQty = 0 Then
            MessageBox.Show("PLEASE ENTER QUANTITY TO TRANSFER", "NiranjanPaints", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtStock.Focus()
            Exit Sub
        End If
        If IntQty > intStock OrElse intStock = 0 Then
            MessageBox.Show("PLEASE ENTER QUANTITY TO TRANSFER", "NiranjanPaints", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtStock.Focus()
            Exit Sub
        End If
        SetItemToGrid()
    End Sub


    Private Sub SetItemToGrid()
        Try
            If funPriIsValidItem() Then
                subPriSetItemInGrid()
                subPriClearItemDtls()
                txtItemCode.Focus()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "")
        End Try
    End Sub
    Private Sub txtAmount_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtItemAmount.LostFocus
        SetItemToGrid()
    End Sub
    Private Function funPriIsValidItem() As Boolean
        Try
            Dim BlnResult As Boolean = True
            If IntItem = 0 Then
                txtItemCode.Focus()
                BlnResult = False
            ElseIf (blnIsColor AndAlso intColor = 0) Then
                txtCLRCODE.Focus()
                BlnResult = False
                'ElseIf intGodownID = 0 Then
                '    txtGoDown.Focus()
                '    BlnResult = False
            ElseIf txtQty.Text = String.Empty OrElse System.Convert.ToInt64(txtQty.Text) <= 0 Then
                txtQty.Focus()
                BlnResult = False
                'ElseIf txtPrice.Text.Trim = String.Empty OrElse System.Convert.ToDouble(txtPrice.Text) <= 0 Then
                '    txtPrice.Focus()
                '    Return False
            End If
            Return BlnResult
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "")
            Return False
        End Try
    End Function

    Private Sub subPriSetItemInGrid()
        Try


            With fgItems

                Dim intCurrentRow As Integer
                For intCurrentRow = 0 To .Rows.Count - 1
                    If IsNothing(.Item(ItemGridColumns.ITEMID, intCurrentRow).Value) OrElse .Item(ItemGridColumns.ITEMID, intCurrentRow).Value.ToString() = String.Empty Then
                        Exit For
                    End If
                Next
                If intCurrentRow = .Rows.Count Then
                    .Rows.Add(1)
                End If

                .Item(ItemGridColumns.CODE, intCurrentRow).Value = txtItemCode.Text

                .Item(ItemGridColumns.ITEMNAME, intCurrentRow).Value = txtItemName.Text
                .Item(ItemGridColumns.CLRCODE, intCurrentRow).Value = txtCLRCODE.Text
                .Item(ItemGridColumns.CLRDESC, intCurrentRow).Value = txtCLRNAME.Text
                .Item(ItemGridColumns.PACK, intCurrentRow).Value = cmbPack.Text
                .Item(ItemGridColumns.STOCK, intCurrentRow).Value = txtStock.Text
                '.Item(ItemGridColumns.RATE, intCurrentRow).Value = txtPrice.Text
                .Item(ItemGridColumns.QTY, intCurrentRow).Value = txtQty.Text
                '.Item(ItemGridColumns.AMOUNT, intCurrentRow).Value = txtItemAmount.Text
                '.Item(ItemGridColumns.DISC, intCurrentRow).Value = txtDisc.Text
                '.Item(ItemGridColumns.DISC_AMT, intCurrentRow).Value = txtDscAmt.Text

                .Item(ItemGridColumns.ITEMID, intCurrentRow).Value = IntItem
                '.Item(ItemGridColumns.GODOWNID, intCurrentRow).Value = intGodownID
                .Item(ItemGridColumns.CLRID, intCurrentRow).Value = intColor
                .Item(ItemGridColumns.PACK_SIZE_ID, intCurrentRow).Value = intPackSizeID
                .Item(ItemGridColumns.PACKUPDATEID_PK, intCurrentRow).Value = intPackUpdateDtl_PK
                .Item(ItemGridColumns.TOPACKUPDATEID_PK, intCurrentRow).Value = intToPackUpdateDtl_PK
                .Item(ItemGridColumns.PACKINGID, intCurrentRow).Value = intPackingID ''used for summary
                '.Item(ItemGridColumns.TAXID, intCurrentRow).Value = intTaxID
                '.Item(ItemGridColumns.TAXCODE, intCurrentRow).Value = TaxCode

                '.Item(ItemGridColumns.GODOW, intCurrentRow).Value = intGodownID
                intCurrentRow = 0

            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "")
        Finally

        End Try
    End Sub
    Sub subPriClearItemDtls()
        Try
            txtItemCode.Text = String.Empty
            txtItemName.Text = String.Empty
            txtCLRCODE.Text = String.Empty
            txtCLRNAME.Text = String.Empty
            cmbPack.SelectedIndex = -1
            txtStock.Text = String.Empty
            txtQty.Text = String.Empty

            txtItemAmount.Text = String.Empty
            txtPrice.Text = String.Empty
            txtDisc.Text = String.Empty
            txtDscAmt.Text = String.Empty

            intPackSizeID = 0
            intColor = 0
            IntItem = 0
            'intFromGodownID = 0
            'intToGodownID = 0
            intPackUpdateDtl_PK = 0
            intToPackUpdateDtl_PK = 0
            intStock = 0
            intPackingID = 0
        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "")
        End Try
    End Sub

    Private Sub fgItems_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles fgItems.KeyDown
        If e.KeyCode = Keys.Enter Then
            '  fgItems_DoubleClick(Nothing, Nothing)
        ElseIf e.KeyCode = Keys.Delete Then
            If MessageBox.Show("Do you want to delete record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = vbYes Then
                SubPriDeleteRecord()
            End If
        End If
    End Sub

    Private Sub fgItems_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles fgItems.DoubleClick
        With fgItems
            If Not IsNothing(.CurrentRow) AndAlso Not IsNothing(.Item(ItemGridColumns.ITEMID, .CurrentRow.Index).Value) Then
                Dim intCurrentRow As Integer = .CurrentRow.Index
                IntItem = .Item(ItemGridColumns.ITEMID, intCurrentRow).Value
                intPackSizeID = .Item(ItemGridColumns.PACK_SIZE_ID, intCurrentRow).Value
                intStock = .Item(ItemGridColumns.STOCK, intCurrentRow).Value
                intColor = .Item(ItemGridColumns.CLRID, intCurrentRow).Value
                intPackUpdateDtl_PK = .Item(ItemGridColumns.PACKUPDATEID_PK, intCurrentRow).Value
                intToPackUpdateDtl_PK = .Item(ItemGridColumns.TOPACKUPDATEID_PK, intCurrentRow).Value
                intPackingID = .Item(ItemGridColumns.PACKINGID, intCurrentRow).Value

                txtQty.Text = .Item(ItemGridColumns.QTY, intCurrentRow).Value
                txtStock.Text = .Item(ItemGridColumns.STOCK, intCurrentRow).Value
                txtItemCode.Text = .Item(ItemGridColumns.CODE, intCurrentRow).Value
                txtItemName.Text = .Item(ItemGridColumns.ITEMNAME, intCurrentRow).Value
                txtCLRCODE.Text = .Item(ItemGridColumns.CLRCODE, intCurrentRow).Value
                txtCLRNAME.Text = .Item(ItemGridColumns.CLRDESC, intCurrentRow).Value

                'txtPrice.Text = .Item(ItemGridColumns.RATE, intCurrentRow).Value
                'txtDisc.Text = .Item(ItemGridColumns.DISC, intCurrentRow).Value
                'txtDscAmt.Text = .Item(ItemGridColumns.DISC_AMT, intCurrentRow).Value
                'txtItemAmount.Text = .Item(ItemGridColumns.AMOUNT, intCurrentRow).Value

                subPriUpdateFromPack()
                cmbPack.SelectedValue = intPackSizeID
                .Rows.Remove(.CurrentRow)
            End If
        End With
    End Sub

    Private Sub SubPriDeleteRecord()
        Try
            With fgItems
                If Not IsNothing(.Item(ItemGridColumns.AMOUNT, .CurrentRow.Index).Value) Then
                    .Rows.Remove(.CurrentRow)
                End If
            End With

        Catch ex As Exception
            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "")
        Finally

        End Try
    End Sub

    '#Region "SEARCH SALE"

    '    Private Sub txtSearch_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs)
    '        If e.KeyCode = Keys.Enter Then
    '            SearchVoucher()
    '            Exit Sub
    '        End If
    '        'If BCommon.ValidateText(txtSearch.Text.Trim, e.KeyCode, "NUM", False) = False Then
    '        '    e.SuppressKeyPress = True
    '        'End If
    '    End Sub

    '    Private Sub SearchVoucher()
    '        Try

    '            If intFromGodownID = 0 OrElse intToGodownID = 0 Then
    '                Return
    '            End If
    '            Call subPriClearItemDtls()

    '            Dim DtbItems As DataTable = clsDStockTransfer.GetTransferDetails(intFromGodownID, intToGodownID)
    '            If DtbItems Is Nothing OrElse DtbItems.Rows.Count = 0 Then
    '                Return
    '            End If
    '            fgItems.Rows.Clear()
    '            Dim intCurrentRow As Integer = 0
    '            For Each ItemToTransfer As DataRow In DtbItems.Rows

    '                If fgItems.Rows.Count <= intCurrentRow Then
    '                    fgItems.Rows.Add(intGrdCntRows)
    '                End If
    '                fgItems.Item(ItemGridColumns.CODE, intCurrentRow).Value = ItemToTransfer.Item("ItemCode") 'txtItemCode.Text

    '                fgItems.Item(ItemGridColumns.ITEMNAME, intCurrentRow).Value = ItemToTransfer.Item("ItemName") ' txtItemName.Text
    '                fgItems.Item(ItemGridColumns.CLRCODE, intCurrentRow).Value = ItemToTransfer.Item("ColorCode") 'txtCLRCODE.Text
    '                fgItems.Item(ItemGridColumns.CLRDESC, intCurrentRow).Value = ItemToTransfer.Item("COLORNAME") 'txtCLRNAME.Text
    '                fgItems.Item(ItemGridColumns.PACK, intCurrentRow).Value = ItemToTransfer.Item("PACK") 'cmbPack.Text
    '                fgItems.Item(ItemGridColumns.STOCK, intCurrentRow).Value = ItemToTransfer.Item("STOCK") 'txtGoDown.Text
    '                'fgItems.Item(ItemGridColumns.RATE, intCurrentRow).Value = ItemToTransfer.Item("SalePrice") 'txtPrice.Text
    '                fgItems.Item(ItemGridColumns.QTY, intCurrentRow).Value = ItemToTransfer.Item("Qty") 'txtQty.Text
    '                'fgItems.Item(ItemGridColumns.AMOUNT, intCurrentRow).Value = ItemToTransfer.Item("Amount") 'txtItemAmount.Text
    '                'fgItems.Item(ItemGridColumns.DISC, intCurrentRow).Value = ItemToTransfer.Item("DISC")
    '                'fgItems.Item(ItemGridColumns.DISC_AMT, intCurrentRow).Value = ItemToTransfer.Item("DISC_AMT")

    '                fgItems.Item(ItemGridColumns.ITEMID, intCurrentRow).Value = ItemToTransfer.Item("ItemID") 'IntItem
    '                'fgItems.Item(ItemGridColumns.GODOWNID, intCurrentRow).Value = ItemToTransfer.Item("GodownId") 'intGodownID
    '                fgItems.Item(ItemGridColumns.CLRID, intCurrentRow).Value = ItemToTransfer.Item("COLORID") 'intColor
    '                fgItems.Item(ItemGridColumns.PACK_SIZE_ID, intCurrentRow).Value = ItemToTransfer.Item("PACKID") 'intPack
    '                fgItems.Item(ItemGridColumns.PACKUPDATEID_PK, intCurrentRow).Value = ItemToTransfer.Item("PackingUpdateID") 'intPackingUpdateID
    '                fgItems.Item(ItemGridColumns.TOPACKUPDATEID_PK, intCurrentRow).Value = ItemToTransfer.Item("ToPackingUpdateID") 'intPackingUpdateID
    '                'fgItems.Item(ItemGridColumns.PACKINGID, intCurrentRow).Value = ItemToTransfer.Item("PackingID") ''FOR SUMARY DETAILS
    '                'fgItems.Item(ItemGridColumns.TAXID, intCurrentRow).Value = ItemToTransfer.Item("TAXID")
    '                'fgItems.Item(ItemGridColumns.TAXAMT, intCurrentRow).Value = ItemToTransfer.Item("TAXAMT")
    '                'fgItems.Item(ItemGridColumns.TAXCODE, intCurrentRow).Value = GetTaxCode(SaleITem.Item("TAXID"))
    '                intCurrentRow += 1
    '            Next

    '        Catch ex As Exception
    '            BCommon.ErrorHandler(ex.ToString, Me.ProductName, Me.Name, "")
    '        End Try
    '    End Sub
    '    'Private Sub subPriFillDetails()

    '    '    Call ClearData()
    '    '    Dim intTempVoucherID As Integer = intVoucherID
    '    '    intVoucherID = intTempVoucherID
    '    '    Dim DtbSale As DataTable = DSale.GetSaleBill(intVoucherID)
    '    '    Dim dtbSaleItems As DataTable = DSale.GetSaleBillItems(intVoucherID)
    '    '    'Dim dtblocTaxes As DataTable = DSale.GetSaleTaxes(intVoucherID)
    '    '    'Dim dtbOtherChrgs As DataTable = 


    '    '    With DtbSale.Rows(0)
    '    '        'S.SeqSaleID,S.PartyCode AS PartyID,P.PartyCode,P.PartyName, S.SaleDate,S.PromoterID,R.PromoterName,R.PromoterCode,S.SiteID,S.Amount,S.OtherCharges,S.TotalTaxes,
    '    '        'S.Discount, S.GrossAmount, S.ShipingAddress, S.SaleType, PriceListID, T.SiteName, T.SiteCode


    '    '        txtVoucher.Text = .Item("SeqSaleID")
    '    '        'TxtFromGodown.Text = .Item("PartyCode")
    '    '        'TxtToGodown.Text = .Item("PartyName")
    '    '        '.Text = .Item("")

    '    '        '''''-------------------------Item Details
    '    '    End With
    '    '    ''''''Fill Sale Details
    '    '    'S.ItemID,P.ProductName,P.ProductCode,S.CLRcode AS CLRID,C.ColorCode,C.ColorDescription, S.PackUpdateID,S.SalePrice,S.Qty,S.Amount,S.SchemeDiscount SELECT S.ItemID,
    '    '    'P.ProductName,P.ProductCode,S.CLRcode AS CLRID,C.ColorCode,C.ColorDescription, S.PackUpdateID,S.SalePrice,S.Qty,S.Amount,S.SchemeDiscount, PCK 
    '    '    Dim intCurrentRow As Integer = 0
    '    '    For Each SaleITem As DataRow In dtbSaleItems.Rows

    '    '        If fgItems.Rows.Count <= intCurrentRow Then
    '    '            fgItems.Rows.Add(intGrdCntRows)
    '    '        End If
    '    '        fgItems.Item(ItemGridColumns.CODE, intCurrentRow).Value = SaleITem.Item("ProductCode") 'txtItemCode.Text

    '    '        fgItems.Item(ItemGridColumns.ITEMNAME, intCurrentRow).Value = SaleITem.Item("ProductName") ' txtItemName.Text
    '    '        fgItems.Item(ItemGridColumns.CLRCODE, intCurrentRow).Value = SaleITem.Item("ColorCode") 'txtCLRCODE.Text
    '    '        fgItems.Item(ItemGridColumns.CLRDESC, intCurrentRow).Value = SaleITem.Item("ColorDescription") 'txtCLRNAME.Text
    '    '        fgItems.Item(ItemGridColumns.PACK, intCurrentRow).Value = SaleITem.Item("PCK") 'cmbPack.Text
    '    '        fgItems.Item(ItemGridColumns.STOCK, intCurrentRow).Value = SaleITem.Item("STOCK") 'txtGoDown.Text
    '    '        'fgItems.Item(ItemGridColumns.RATE, intCurrentRow).Value = SaleITem.Item("SalePrice") 'txtPrice.Text
    '    '        fgItems.Item(ItemGridColumns.QTY, intCurrentRow).Value = SaleITem.Item("Qty") 'txtQty.Text
    '    '        fgItems.Item(ItemGridColumns.AMOUNT, intCurrentRow).Value = SaleITem.Item("Amount") 'txtItemAmount.Text
    '    '        'fgItems.Item(ItemGridColumns.DISC, intCurrentRow).Value = SaleITem.Item("DISC")
    '    '        'fgItems.Item(ItemGridColumns.DISC_AMT, intCurrentRow).Value = SaleITem.Item("DISC_AMT")

    '    '        fgItems.Item(ItemGridColumns.ITEMID, intCurrentRow).Value = SaleITem.Item("ItemID") 'IntItem
    '    '        fgItems.Item(ItemGridColumns.GODOWNID, intCurrentRow).Value = SaleITem.Item("GodownId") 'intGodownID
    '    '        fgItems.Item(ItemGridColumns.CLRID, intCurrentRow).Value = SaleITem.Item("CLRID") 'intColor
    '    '        fgItems.Item(ItemGridColumns.PACK_SIZE_ID, intCurrentRow).Value = SaleITem.Item("PackSizeID") 'intPack
    '    '        fgItems.Item(ItemGridColumns.PACKUPDATEID_PK, intCurrentRow).Value = SaleITem.Item("PackUpdateIDPK") 'intPackingUpdateID
    '    '        fgItems.Item(ItemGridColumns.PACKINGID, intCurrentRow).Value = SaleITem.Item("PackingID") ''FOR SUMARY DETAILS
    '    '        'fgItems.Item(ItemGridColumns.TAXID, intCurrentRow).Value = SaleITem.Item("TAXID")
    '    '        'fgItems.Item(ItemGridColumns.TAXAMT, intCurrentRow).Value = SaleITem.Item("TAXAMT")
    '    '        'fgItems.Item(ItemGridColumns.TAXCODE, intCurrentRow).Value = GetTaxCode(SaleITem.Item("TAXID"))
    '    '        intCurrentRow += 1
    '    '    Next
    '    'End Sub
    '#End Region



End Class

